<template>
  <div class="footer1">
     <ul>
         <li v-for="(value,index) in data" v-bind:style="{ 'background':value.index!='card'||time!=0 ?value.styleObject.background : value.styleObject.timeBackground, 'width': value.styleObject.width,'color':value.spanStyle.color}" @click="to(value.index)">
             <div v-if="value.hasIcon==1">
                 <img :src="value.tag==1 ? value.selectImg : value.backgroundImg" />
             </div>
           <span v-bind:style="{'color':value.spanStyle.color,'margin-top':value.spanStyle.margin_top}">
               {{value.title}}
               <span v-if="value.index!='card'||time==0? false : true">{{time}}s后可以打卡</span>
           </span>
         </li>
     </ul>
  </div>
</template>

<script>
export default {  
  props:['data'],
  data (){
    return {
      data1:[],
    }
  },
  computed:{
    time(){
      return this.$store.state.setTime
    }
  },
  methods:{
    to(index){
      var _this=this;
      if(index=="first")    //跳转到首页
      {
        wx.navigateTo({
          url:'../classSelect/main'
        })
      }
      if(index=="discuss")   //跳转到用户打卡信息列表页面
      {
        wx.navigateTo({
          url:'../logs/main'
        })
      } 
      if(index=="me")   //跳转到用户打卡信息列表页面
      {
        wx.navigateTo({
          url:'../me/main'
        })
      } 
      if(index=="card")    //跳转到答题页面
      {
        if(this.time=="0")
        {
          wx.navigateTo({
          url:'../answer/main' 
          })
          this.$store.dispatch('setdiscussType','daka')    //因为打完卡会跳转到发布页面  这里设置当前发布的内容是打卡信息
        }else
        {
          console.log('倒计时30S还没到')
        }
        
      }
      if(index=='yjfk')
      {
        var userToken=wx.getStorageSync('userToken');
        var content=this.$store.state.content;
        wx.request({
          url:'https://daka.rzkeji.com/api/ucenter/set-feedback',
          data:{
            daka_token:userToken,
            content:content
          },
          method:'POST',
          header:{
            "content-type":"application/json"
          },
          success(res){
            if(res.data.level=="success")
            {
              wx.showToast({
                title:res.data.message,
                icon:'success',
                duration:2000
              })
              setTimeout(function(){
                wx.navigateTo({
                url:'../me/main' 
                })
              },2500)
            }
          }
        })
      }
      if(index=="send")    //点击发布 ，发送内容详细信息
      {
        var dakaId=this.$store.state.discussType == "comment" ?this.$store.state.commentId :this.$store.state.dakaId;
        var type=this.$store.state.discussType;
        var du_id=this.$store.state.du_id;
        var content=this.$store.state.content;
        var userToken=wx.getStorageSync('userToken');
        wx.request({
          url:'https://daka.rzkeji.com/api/daka/send-daka-content',
          method: "post",
         header: {
          'content-type': 'application/json'
         },
         data:{
          d_id:dakaId,
          du_id:du_id,
          content:content,
          type:type,
          daka_token:userToken
         },
         success(res){
          if(res.data.level=="success")
          {
          wx.request({       //获取用户的打卡信息列表
          url: 'https://daka.rzkeji.com/api/daka/get-daka-detail', //仅为示例，并非真实的接口地址
          header: {
          'content-type': 'application/json' // 默认值
          },
          data:{
            id:dakaId
          },
          success(res){
          var details=res.data.data;
          _this.data1=[];
          _this.$store.dispatch('setFooter',res);
          for(var i=details.daka_user_list.length-1;i>=0;i--)
          {
          _this.$store.dispatch('setCommentId',details.id)
          _this.data1.push({
            "id":details.daka_user_list[i].id,
            "photo_url":details.daka_user_list[i].photo_url,
            "sex":details.daka_user_list[i].sex,
            "nickname":details.daka_user_list[i].nickname,
            "msg_time":details.daka_user_list[i].daka_time,
            "msg_content":details.daka_user_list[i].content,
            "like_list":details.daka_user_list[i].like_list,
            "comment_list":details.daka_user_list[i].comment_list,
            "keep_day":details.daka_user_list[i].keep_day,
            "goodImg":'http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/daka/icon/like.png'
          }) 
          }
          _this.$store.dispatch('setComment',_this.data1)
          for(var j=0;j<_this.data1.length;j++)
          {
            for(var h=0;h<_this.data1[j].like_list.length;h++)
            { 
              if(_this.data1[j].like_list[h].nickname==_this.$store.state.userInfo.nickName)
              {
              _this.data1[j].goodImg="http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/daka/icon/like-active.png"
              }
            }
          }
          if(_this.$store.state.discussType=='comment')
          {
            wx.navigateTo({
            url:'../logs/main' 
            })
          }else{
            wx.navigateTo({
            url:'../share/main' 
            })
          }
          }
          })
        }else{
          wx.showToast({
            icon:"none",
            title:res.data.message,
            duration:3000,
            success(){
              setTimeout(function(){
                  wx.navigateTo({
                  url:'../classSelect/main'
                  })
              },3000)
            }
          })
        }

      }
        })
        
      }
    }
  }
}
</script>

<style scoped>
.footer1{width: 100%;height: 50px;position: fixed;left: 0;bottom: 0;}
.footer1 ul{width: 100%;height: 50px;display: flex;justify-content: row;text-align: center;font-size: 20px;text-align: center;}
li{width: 100%;height: 100%;}
img{width: 20px;height:20px;display: block;margin:5px auto;}
li span{display: block;height: 20px;font-size: 14px;margin-left: 1px;}
li span span{float: right;height: 20px;line-height: 20px;margin-right:30px;}
</style>
